package com.example.forum_system.dao;

import com.example.forum_system.model.Article;
import com.example.forum_system.model.VO.ArticleVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    //1.新增文章
    @Insert("insert into t_article(boardId, userId, title, content, createTime, updateTime,likeCount,visitCount,state,deleteState)values(#{boardId}, #{userId}, #{title}, #{content}, #{createTime}, #{updateTime},#{likeCount},#{visitCount},#{state},#{deleteState})")
    int insertArticle(Article row);

    //2.删除文章
    @Delete("delete from t_article where id=#{id}")
    int deleteArticle(@Param("id") long id);

    //3.获取文章,根据文章id
    @Select("select * from t_article where id=#{id} and deleteState=0")
    ArticleVO selectOneArticleById(@Param("id")long id);

    //4.获取所有文章列表
    @Select("select * from t_article where deleteState=0 order by updateTime desc")
    List<ArticleVO> selectAllArticle();

    //5.获取文章列表,根据用户id
    @Select("select * from t_article where userId=#{userId} order by updateTime desc")
    List<ArticleVO> selectArticlesByUser(@Param("userId")long userId);

    //6.获取文章列表,根据板块id
    @Select("select * from t_article where boardId=#{boardId} order by updateTime desc")
    List<ArticleVO> selectArticlesByBoard(@Param("boardId")long boardId);

    //7.获取文章总数,根据用户id
    @Select("select COUNT(id) from t_article where userId=#{userId}")
    int selectCountByUser(@Param("userId") long userId);

    //8.获取文章总数,根据板块id
    @Select("select COUNT(id) from t_article where boardId =#{boardId}")
    int selectCountByBoard(@Param("boardId") long boardId);

    //9.修改文章,修改[标题,正文,修改时间]
    @Update("update t_article set title=#{title},content=#{content},updateTime=#{updateTime} where id=#{id}")
    int updateArticle(Article article);
    //10.文章点赞数+1
    @Update("update t_article set likeCount=likeCount+1 where id=#{id}" )
    int addLikeCount(@Param("id") long id);
    //11.文章访问量+1
    @Update("update t_article set visitCount=visitCount+1 where id=#{id}")
    int addVisitCount(@Param("id") long id);

//    int insertSelective(Article row);
//
//    Article selectByPrimaryKey(Long id);
//
//    int updateByPrimaryKeySelective(Article row);
//
//    int updateByPrimaryKeyWithBLOBs(Article row);
//
//    int updateByPrimaryKey(Article row);
}